package com.nowcoder.chapter3.part37;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * Deque
 */
public class QueueDemo2 {

    public static void main(String[] args) {
        // 双端队列
        Deque queue = new ArrayDeque();
        queue.offer("Mary");
        queue.offer("Lily");
        queue.offer("Tony");
        System.out.println(queue);

        queue.offerFirst("John");
        System.out.println(queue);

        queue.offerLast("Lucy"); // == offer()
        System.out.println(queue);

        System.out.println(queue.peekFirst()); // == peek()
        System.out.println(queue.peekLast());
        System.out.println(queue);

        while (queue.size() > 0) {
//            System.out.println(queue.pollLast());
            System.out.println(queue.pollFirst()); // == poll()
        }
        System.out.println(queue);

        // 栈
        Deque stack = new ArrayDeque();
        stack.push("唐僧");
        stack.push("悟空");
        stack.push("八戒");
        stack.push("沙僧");
        System.out.println(stack);

        while (stack.size() > 0) {
            System.out.println(stack.pop());
        }
        System.out.println(stack);
    }

}
